#include "IndexBuffer.h"


IndexBuffer::IndexBuffer(void) : Resource()
{

}


IndexBuffer::~IndexBuffer(void)
{
}

void IndexBuffer::Bind()
{
	if(IsAllocated() == false)
	{
		glGenBuffers(1,&buffer);
		SetAllocated();
	}

	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,buffer);
}


void IndexBuffer::Unbind()
{
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
}

void IndexBuffer::Dispose()
{
	Unbind();
	glDeleteBuffers(1,&buffer);
}

void IndexBuffer::BufferData(unsigned int lenght,void * data,Usage usage)
{
	if(usage == STATIC)
	{
		glBufferData(GL_ELEMENT_ARRAY_BUFFER,lenght,data,GL_STATIC_DRAW);
	}
	else 
	{
		glBufferData(GL_ELEMENT_ARRAY_BUFFER,lenght,data,GL_DYNAMIC_DRAW);
	}
}